define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/shop/index' + location.search,
                    add_url: 'shop/shop/add',
                    edit_url: 'shop/shop/edit',
                    del_url: 'shop/shop/del',
                    multi_url: 'shop/shop/multi',
                    import_url: 'shop/shop/import',
                    table: 'shop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'shop_type_id', title: __('Shop_type_id')},
                        {field: 'type.name', title: __('Type.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'num', title: __('Num')},
                        // {field: 'detail', title: __('Detail'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'detail_image', title: __('Detail_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"2":__('Status 2'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        // {field: 'enmo', title: __('Enmo'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'provincial_id', title: __('Provincial_id')},
                        // {field: 'is_g_top', title: __('Is_g_top'), searchList: {"0":__('Is_g_top 0'),"1":__('Is_g_top 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'is_s_top', title: __('Is_s_top'), searchList: {"0":__('Is_s_top 0'),"1":__('Is_s_top 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'g_endtime', title: __('G_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 's_endtime', title: __('S_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'is_status', title: __('Is_status'), searchList: {"0":__('Is_status 0'),"1":__('Is_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,

                            buttons:[
                                {
                                    name: 'plus',
                                    title: __('通过审核'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: 'fa fa-check',
                                    extend: 'data-area=\'["70%", "80%"]\' data-shade=\'[0.5, "#000"]\'',
                                    // url: 'work_order/state?status=complete',
                                    confirm: '确定通过审核吗',

                                    url: function (row) {
                                        return 'shop/shop/examine?ids='+row.id;
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    visible: function (row) {
                                        if (row.status == '0') {
                                            return true;
                                        }

                                    }
                                },
                                {
                                    //不通过审核 代码逻辑尚未完善
                                    name: 'plus',
                                    title: __('不通过审核'),
                                    classname: 'btn btn-xs btn-danger  btn-dialog',
                                    icon: 'fa fa-close',
                                    extend: 'data-area=\'["30%", "40%"]\' data-shade=\'[0.5, "#000"]\'',
                                    url: function (row) {
                                        return 'shop/shop/failed?ids='+row.id;
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    visible: function (row) {
                                        if (row.status == '0') {
                                            return true;
                                        }

                                    }
                                },
                            ]





                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        failed:function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
